const http = require("http")
const server = http.createServer()

server.on("request", (req, res) => {
    const url = req.url
    const method = req.method
    let content = '404 Not Found'
    console.log(`有人访问服务器 ${url} 方法为 ${method}`)

    res.setHeader("Content-Type", "text/html; charset=utf-8")

    if (url === '/' || url === '/index.html') {
        content = '<h1>首页</h1>'
    } else if (url === '/about.html') {
        content = '<h1>关于</h1>'
    }
    res.end(content)
})

server.listen(8080, () => {
    console.log("服务器已经启动")
})